starter.controller('busCtrl', ['$rootScope','$window','$state','$ionicHistory','$timeout','$ionicScrollDelegate', '$scope', 'XCode','Page','ApiEndpoint',
    function($rootScope,$window,$state,$ionicHistory,$timeout,$ionicScrollDelegate, $scope, XCode, Page,ApiEndpoint) {

        $scope.resCheckFuzzyQueryUrl = ApiEndpoint.resCheckFuzzyQueryUrl;
        //$scope.$on('$ionicView.afterEnter', function() {
        //    setTimeout(function(){
        //        if(window.mobileData != undefined && window.mobileData != '') {
        //            var params = window.mobileData.split("&");
        //            for (var i = 0; i < params.length; i++) {
        //                var eachParams = params[i].split('=');
        //                $rootScope[eachParams[0]] = eachParams[1];
        //            }
        //            //XCode.init();
        //        } else {
        //            window.webkit.messageHandlers.mobileAlert.postMessage({title:'fail',content:window.mobileData.toString(),action:false})
        //        }
        //    },500)
        //}, false);
        $scope._pageSize = 10;
        $scope._pageIndex = 0;
        $scope.search = {};
        $scope.search.queryType = '1'; //车辆;

        //定义自动查询
        $scope.autoSearch = {

        };

        $scope.changeSearchVal = function(selectVal) {
            Page.ajaxPostQuiet(ApiEndpoint.queryBusOrStopUrl, {param : selectVal,queryType : '1',
                _pageSize : $scope._pageSize, _pageIndex : $scope._pageIndex}, function (resp) {
                $scope.busData = resp.data;
            });
        };

        $scope.viewMediaImg = function(resource) {
            $scope.Url = "http://10.100.235.22/download/image/20161201/04a32bf33922482bbf480c8f234a2076.jpg";                   //$scope定义一个变量Url，这里会在大图出现后再次点击隐藏大图使用
            $scope.bigImage = true;
        };

        $scope.hideBigImage = function () {
            $scope.bigImage = false;
        };
        $scope.indexTitle = "图片浏览";
        $scope.bigImage = false;    //初始默认大图是隐藏的
        $scope.imageIndex = -1;//当前展示的图片

        //点击图片放大
        $scope.shouBigImage = function (imageName, imageIndex) {  //传递一个参数（图片的URl）
            $scope.imageIndex = imageIndex;
            $scope.Url = imageName;                   //$scope定义一个变量Url，这里会在大图出现后再次点击隐藏大图使用
            $scope.bigImage = true;                   //显示大图
        };

        //及时定位
        $scope.viewCurrent = function(busInfo) {
            //var alertPopup=$ionicPopup.alert({
            //    title: '提示',
            //    template: "弹出第一alert!"
            //})
            ////window.alert("1321321");
            ////var param = {'title' :'1111','content':'112312321'};
            //mobileAlert(param);

            //window.webkit.messageHandlers.mobileAlert.postMessage({title:'提示',content:'内容',action:false})
            var transParams = {};
            transParams.busId = busInfo.busId;
            transParams.lineNo = busInfo.lineNo;
            transParams.vehicleNo = busInfo.vehicleNo;
            $state.go("busMapInfo",{transParams:transParams});
        }
    }]);
